package cn.edu.hbpu.utils;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * @author lcy
 * @date 2022/8/14 15:56
 * @description 将前端的 datetimepicker的日期时间转为LocalDateTime
 */
public class DateTimeFormat {

    public static LocalDateTime parseTimeToUtc(String time) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.ENGLISH);
        LocalDateTime ldt = LocalDateTime.parse(time, df);
        ZoneId currentZone = ZoneId.of("UTC");
        ZoneId newZone = ZoneId.of("Asia/Shanghai");
        return ldt.atZone(currentZone).withZoneSameInstant(newZone).toLocalDateTime();
    }
}
